<template>
  <div class="home">
    <div class="header">
      <Header></Header>
      <ly-tab
        v-model="selectedId"
        :items="items"
        :options="options"
        @change="lyTab"
      >
      </ly-tab>
    </div>

    <div class="container">
      <div v-for="(item, index) in newData" :key="index">
        <Swiper v-if="item.type == 'swiperList'" :dataList="item.data"></Swiper>

        <Icons v-if="item.type == 'iconsList'" :dataList="item.data"> </Icons>

        <Recommend
          v-if="item.type == 'recommendList'"
          :dataList="item.data"
        ></Recommend>

        <Ad v-if="item.type == 'adList'" :dataList="item.data"></Ad>
      </div>
    </div>

    <Tabbar></Tabbar>
  </div>
</template>

<script>
import Header from "@/components/home/Header";
import Swiper from "@/components/home/Swiper";
import Icons from "@/components/home/Icons";
import Recommend from "@/components/home/Recommend.vue";
import Ad from "@/components/home/Ad.vue";
import http from "@/common/api/request.js";
import Tabbar from "@/components/common/Tabbar.vue";

export default {
  name: "Home",
  data() {
    return {
      selectedId: 0,
      items: [],
      newData: [],
      options: {
        activeColor: "red",
      },
    };
  },
  components: {
    Header,
    Swiper,
    Icons,
    Recommend,
    Ad,
    Tabbar,
  },
  created() {
    this.httpInit();
  },
  methods: {
    //请求数据
    httpInit() {
      http
        .$axios({
          url: "/api/index_list/0/data/1",
        })
        .then((res) => {
          this.items = res.topBar;
          this.newData = res.data;
        });
    },
    lyTab(item, index) {
      this.addData(index);
    },
    addData(index) {
      http
        .$axios({
          url: "/api/index_list/" + index + "/data/1",
        })
        .then((res) => {
          if (res.constructor != Array) {
            this.newData = res.data;
          } else {
            this.newData = res;
          }
        });
    },
  },
};
</script>

<style scoped lang='scss'>
.header {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  width: 100%;
  background-color: #fff;
}
.container {
  padding-top: 109px;
}
</style>


